﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using VisionCloud.Domain.Common;
using VisionCloud.Domain.DtoModel.Ms;
using VisionCloud.Domain.Filters;
using VisionCloud.Service.Ms;

namespace VisionCloud.Api.Controllers.Ms
{

    /// <summary>
    /// 算法规则模板
    /// </summary>
    [SystemModule("算法规则模板")]
    [ApiAuthorize(PolicyEnum.RequireRolePermission)]
    [ApiVersion("1.0")]
    [Route("api/ms/[controller]/[Action]")]
    [ApiExplorerSettings(GroupName = "算法规则模板")]
    public class AlgorithmParamTemplateController : ApiBaseController
    {
        public AlgorithmParamTemplateService AlgorithmParamTemplateService { get; set; }

        /// <summary>
        /// 根据项目ID获取算法模板
        /// </summary>
        /// <param name="projectId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiPageResult<MsAlgoTempDto>> GetAlgoTempByProjID(Guid projectId)
        {
            var algoTemps = await AlgorithmParamTemplateService.GetAlgorithmTemplates(projectId);
            return new ApiPageResult<MsAlgoTempDto> { PageData = algoTemps, Total = (long)algoTemps?.Count };

        }


        [HttpGet]
        public async Task<ApiResult> GetAlgorithmParamTemplateDetail(Guid algorithmParamTemplateGuid)
        {
            return await TryCatchAsync(AlgorithmParamTemplateService.GetAlgorithmParamTemplateDetail(algorithmParamTemplateGuid));
        }
        /// <summary>
        /// 软删除算法模板
        /// </summary>
        /// <param name="algoTempId">算法模板Id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> DeleteAlgoTempById(Guid algoTempId)
        {
            return await TryCatchAsync(AlgorithmParamTemplateService.DeleteAlgorithmTemplate(algoTempId, TokenModel.YunUserGuid));
        }

        /// <summary>
        /// 保存算法参数模板
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> SaveAlgorithmParamTemplateDetail([FromBody] List<MsAlgorithmParamTemplateItemDto> model)
        {
            return await TryCatchAsync(AlgorithmParamTemplateService.SaveAlgorithmParamTemplateDetail(model, TokenModel.Id));
        }
    }
}
